// Copyright [2020] <Weaverzhu>
#include <bits/stdc++.h>
using namespace std;
// #define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
#define dbg(x...) { cerr << "\033[32;1m" << #x << " -> "; err(x); }
void err() { cerr << "\033[39;0m" << endl; }
template<typename T, typename... A>
void err(T a, A... x) { cerr << a << ' '; err(x...); }
#else
#define dbg(...)
#endif
 
 
const int N = 1e6+50;
 
int minp[N], prime[N], pcnt;
typedef long long LL;
 
LL a[N], s[N];
int id[N];
LL cnt[N];
 
void init()
{
    for (int i=2; i<N; ++i) {
        if (!minp[i]) {
            minp[i] = i;
            prime[pcnt++] = i;
            id[i] = pcnt-1;
        }
        for (int j=0; j<pcnt; ++j) {
            LL nextp = 1LL * i * prime[j];
            if (nextp >= N) break;
            if (!minp[nextp]) minp[nextp] = prime[j];
            if (i % prime[j] == 0)
                break;
        }
    }
}
 
LL bin(LL a, LL b, LL p)
{
    LL res = 1;
    for (a%=p; b; b>>=1, a=a*a%p)
        if (b & 1)
            res = res * a % p;
    return res;
}
 
LL mul(LL u, LL v, LL p) { // 卡常
    LL t = u * v - LL((long double) u * v / p) * p;
    return t < 0 ? t + p : t;
}
 
bool checkQ(LL a, LL n) {
    if (n == 2 || a >= n) return 1;
    if (n == 1 || !(n & 1)) return 0;
    LL d = n - 1;
    while (!(d & 1)) d >>= 1;
    LL t = bin(a, d, n);  // 不一定需要快速乘
    while (d != n - 1 && t != 1 && t != n - 1) {
        t = mul(t, t, n);
        d <<= 1;
    }
    return t == n - 1 || d & 1;
}
 
bool primeQ(LL n) {
    static vector<LL> t = {2, 325, 9375, 28178, 450775, 9780504, 1795265022};
    if (n <= 1) return false;
    for (LL k: t) if (!checkQ(k, n)) return false;
    return true;
}
 
// pair<int, LL> cnt(LL a[], LL l, LL r) {
//     int lb = lower_bound(a, a+n, l) - a,
//     rb = lower_bound(a, a+n, r) - a;
//     return make_pair(rb-lb, s[rb-1] - s[lb-1]);
// }
 
mt19937 mt(12345);
LL pollard_rho(LL n, LL c) {
    LL x = uniform_int_distribution<LL>(1, n - 1)(mt), y = x;
    auto f = [&](LL v) { LL t = mul(v, v, n) + c; return t < n ? t : t - n; };
    while (1) {
        x = f(x); y = f(f(y));
        if (x == y) return n;
        LL d = gcd(abs(x - y), n);
        if (d != 1) return d;
    }
}
 
LL fac[100], fcnt; // 结果
void get_fac(LL n, LL cc = 19260817) {
    for (int i=0; i<pcnt; ++i)
        if (n % prime[i] == 0)
        {
            fac[fcnt++] = prime[i];
            while (n % prime[i] == 0) n /= prime[i];
        }
    if (n > 1) fac[fcnt++] = n;
}
int ans, n;
void tryit(LL p)
{
    static unordered_set<LL> S;
    if (S.count(p)) return;
    S.insert(p);
    // dbg(p);
    LL tans = 0;
    for (int i=0; i<n; ++i)
    {
        if (a[i] < p)
            tans += p-a[i]%p;
        else
            tans += min(a[i]%p, (p-a[i]%p));
        if (tans >= ans)
            return;
    }
    ans = tans;
}
void try2(LL x)
{
    static unordered_set<LL> S;
    if (S.count(x)) return;
    S.insert(x);
    if (x <= 2)
        return;
 
    fcnt = 0;
    get_fac(x);
    sort(fac, fac+fcnt);
    fcnt = unique(fac, fac+fcnt) - fac;
    for (int i=0; i<fcnt; ++i)
    {
            tryit(fac[i]);
    }
}
pair<int, int> dat[N];
 
int main(int argc, char const *argv[]) {
    scanf("%d", &n);
    ans = 0;
    init();
    for (int i=0; i<n; ++i) {
        scanf("%lld", &a[i]);
        fcnt = 0;
        ans += a[i] & 1;
    }
    for (int i=0; i<20; ++i)
    {
        int p = mt() % n;
        try2(a[p]+1);
        try2(a[p]-1);
        try2(a[p]);
    }
    // for (int i=0; i<pcnt; ++i)
    //     dat[i] = make_pair(cnt[i], i);
    // sort(dat, dat+pcnt);
    // reverse(dat, dat+pcnt);
    // for (int i=0; i<pcnt; ++i)
    // {
    //     if (n-dat[i].first >= ans)
    //         break;
    //     tryit(prime[dat[i].second]);
    // }
    printf("%d\n", ans);
    return 0;
}